<?php
/**
 * Copyright (C) 2013  Artur Tolstenco
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

abstract class Agenziaterritorio_Mapper_Abstract {
    /**
     * The table used by this mapper
     *
     * @var Zend_Db_Table_Abstract
     */
    protected $_dbTable;

    /**
     * The table object to be used
     *
     * @var string
     */
    protected $table_name;
	
	public function setDbTable($dbTable) {
		if (is_string($dbTable)) 
			$dbTable = new $dbTable();
		
		if (! $dbTable instanceof Zend_Db_Table_Abstract)
			throw new Exception('Invalid table data gateway provided');
		
		$this->_dbTable = $dbTable;
		return $this;
	}
	
	/**
	 * Returns the used db table
	 *
	 * @return Zend_Db_Table_Abstract
	 */
	public function getDbTable() {
		if (null === $this->_dbTable) {
			$this->setDbTable($this->table_name);
		}
		return $this->_dbTable;
	}
}